﻿package code.admin 
{

	import flash.display.*;
	import gemini.utils.*
	import flash.events.*
	import caurina.transitions.*
	public class ModuleItem extends Sprite
	{
		var img;
		var mainframe;
		var modLink;
		public var modclip
		public var mynum;
		public var sx,sy;
		var preview;
		public function ModuleItem(mf,lnk)
		{
			mainframe=mf;
			modLink=lnk;
			img=new moduleicon();
			img.bck.gotoAndStop(1);
			img.txt.text="Loading";
			addChild(img);
			
			
			var bl=new BulkLoader();
			bl.addFile(mainframe.mainframe.path+"modules/"+modLink,this,"modclip");
			bl.onComplete(init);
			bl.onProgress(prog);
			bl.loadFiles();
			
			
		}
		private function init(e)
		{
			
			sx=x;
			sy=y;
			/*try
			{
				img.txt.text=modclip.modname[mainframe.mainframe.mainframe.lang];
			}
			catch(e)
			{
				img.txt.text=modLink;
			}*/
			
			/*
			var scale;
			if(modclip.width>modclip.height)
			{
				scale=80/modclip.width;
			}
			else
			{
				scale=80/modclip.height;
			}
			
			modclip.mainframe=mainframe.mainframe.mainframe;
			modclip.scaleX=scale;
			modclip.scaleY=scale;
			*/
			
			
			try
			{
				
				
				var icn=modclip.ModuleIcon();
				var scl=25/icn.width;
				icn.scaleX=scl;
				icn.scaleY=scl;
				img.gotoAndStop("preview");
				img.holder.addChild(icn);
				//removeChild(img);
			}
			catch(e)
			{
				trace("NO ICON");
				img.gotoAndStop("noicon");
				//img.txt.text=modLink;
			}
			img.btn.addEventListener(MouseEvent.MOUSE_DOWN,dragMe);
			img.btn.addEventListener(MouseEvent.MOUSE_UP,dontDragMe)
			mainframe.arrangeAll();
		}
		
		private function dragMe(e)
		{
			
			this.startDrag();
		}
		private function dontDragMe(e)
		{
			this.stopDrag();
			x=sx;
			y=sy;
			var obj={"clip":modLink,"params":{}}
			mainframe.mainframe.mainframe.makeModule(obj)
			//stage.removeEventListener(MouseEvent.MOUSE_MOVE,moveMe);
			
			
			
			
		}
		private function moveMe(e)
		{
			trace("MOVING");
		}
		private function prog(e)
		{
			img.bck.gotoAndStop(Math.round((e.loadedsize/e.totalsize)*100)/1);
			
		}

	}

}